<!--
 * @Author: your name
 * @Date: 2022-01-15 09:16:13
 * @LastEditTime: 2022-01-16 09:35:07
 * @LastEditors: Please set LastEditors
 * @Description: 首页
 * @FilePath: \uniapp\src\pages\index\index.vue
-->
<template>
  <view>
    <!-- 搜索框 -->
    <searchInput></searchInput>
    <!-- 轮播图 -->
    <u-swiper :list="swiperList" name="image_src" height="340"></u-swiper>
    <!-- 导航 -->
    <view class="nav u-flex">
      <navigator
        v-for="item in navList"
        :key="item.name"
        class="u-flex-1 u-p-15"
      >
        <u-image mode="widthFix" :src="item.image_src" width="100%"></u-image>
      </navigator>
    </view>
    <!-- 楼层数据 -->
    <view class="indexFloor">
      <view
        class="groupFloor"
        v-for="item1 in floorList"
        :key="item1.floor_title.name"
      >
        <view class="titleFloor">
          <u-image
            mode="widthFix"
            :src="item1.floor_title.image_src"
            width="100%"
          ></u-image>
        </view>
        <view class="listFloor">
          <navigator v-for="item2 in item1.product_list" :key="item2.name">
            <u-image
              :src="item2.image_src"
              mode="scaleToFill"
              width="100%"
              height="100%"
            ></u-image>
          </navigator>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      // 轮播数组
      swiperList: [],
      // 导航数组
      navList: [],
      // 楼层数组
      floorList: [],
    };
  },
  onLoad() {
    this.getSwiperList();
    this.getNavList();
    this.getFloorList();
  },
  methods: {
    async getSwiperList() {
      // const [err, res] = await uni.request({
      //   url: "https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata", //接口地址
      // });
      // this.swiperList = res.data.message;
      this.swiperList = await this.$u.http.get("/home/swiperdata");
    },
    async getNavList() {
      this.navList = await this.$u.http.get("/home/catitems");
    },
    async getFloorList() {
      this.floorList = await this.$u.http.get("/home/floordata");
    },
  },
};
</script>

<style lang="scss" scoped>
.groupFloor {
  margin-top: 10rpx;
}
.listFloor {
  padding: 0 12rpx;

  /* 清除浮动 */
  overflow: hidden;
  navigator {
    float: left;
  }
  // 第一张图片
  navigator:nth-child(1) {
    width: 232rpx;
    height: 386rpx;
  }
  /* 后四张图片 */
  navigator:nth-last-child(-n + 4) {
    width: 233rpx;
    height: 188rpx;
  }
  /* 2 和 4 图片 */
  navigator:nth-child(2),
  navigator:nth-child(4) {
    margin: 0 15rpx;
  }

  /* 后两张图片 */
  navigator:nth-last-child(-n + 2) {
    margin-top: 10rpx;
  }
}
</style>
